SOCAT udp
socat udp
Table of Content
Connected vs unconnected#
UDP sockets can be “connected” (or “established”) or “unconnected”.
- Connected sockets have a full 4-tuple associated {source ip, source port, destination ip, destination port}
- Unconnected sockets have 2-tuple {bind ip, bind port}.
unconnected#

server
socat UDP-RECV:1234 -
client
socat STDIO udp-sendto:127.0.0.1:1234
Connection established only when data send
ss -panu sport = :1234 or dport = :1234 | cat
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
UNCONN 0 0 0.0.0.0:1234 0.0.0.0:* users:(("socat",pid=144971,fd=5))
Demo: Test connected server#
server
socat UDP-RECV:1234 -
client 1
socat STDIO udp-sendto:127.0.0.1:1234
# send data
client 2
socat STDIO udp-sendto:127.0.0.1:1234
# send data
connected#

server
socat udp-l:1234 -
client
socat STDIO udp:127.0.0.1:1234
Connection established when call connect
ss -panu sport = :1234 or dport = :1234 | cat
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
ESTAB 0 0 127.0.0.1:47917 127.0.0.1:1234 users:(("socat",pid=144636,fd=5))
UNCONN 0 0 0.0.0.0:1234 0.0.0.0:* users:(("socat",pid=144633,fd=5))
Demo: Test connected server#
- Establish server
- Client Connect
- Second client connect and try send data
server
socat udp-l:1234 -
client 1
socat STDIO udp:127.0.0.1:1234
# send data
client 2
socat STDIO udp:127.0.0.1:1234
#
2022/06/28 21:42:56 socat[145414] E read(5, 0x556853768010, 8192): Connection refused
echo server#
terminal1 - server
# udp server
socat -v udp-l:1234,fork exec:'/bin/cat'
terminal1 - client
nc -u 127.0.0.1 1234
# or
socat - udp:127.0.0.1:1234
Broadcasting / Multicasting / Unicasting#

Broadcasting#
server / listener
socat udp-recv:1234 -
client
socat - UDP-DATAGRAM:192.168.1.255:1234,broadcast,sp=11111
# tcpdump
sudo tcpdump -n -i <eth_name> udp
192.168.1.207.11111 > 192.168.1.255.1234: UDP, length 3
summary#
# connected
# server
socat STDIO UDP-LISTEN:11111
# client
socat - UDP:localhost:11111
# unconnected
# server
socat UDP-RECV:11111 STDOUT
# client
socat STDIN UDP-SENDTO:127.0.0.1:11111
# Server
socat UDP-RECVFROM:11111,fork STDOUT